package com.gwcloud.leetcode.offers;

import java.util.Stack;

/** 
* @ClassName   : Leetcode0310 
* @author      : ganwei 
* @date        : 2020年6月3日 
* @Description : TODO 
*/
public class Leetcode0310 {
    public boolean validateStackSequences(int[] pushed, int[] popped) {
    	Stack<Integer> s = new Stack<Integer>();
    	int indexpop = 0;
    	for(int num : pushed) {
    		if(num != popped[indexpop]) {
    			s.push(num);
    		}
    		if(num == popped[indexpop]) {
    			indexpop++;
    			while(indexpop < popped.length && !s.isEmpty() && s.peek() == popped[indexpop]) {
    				s.pop();
    				indexpop++;
    			}
    		}
    	}
    	return indexpop == popped.length;
    }
    /**
     * -主函数
     */
    public static void main(String[] args) {
    	int[] pushed = {1,0};
    	int[] popped = {1,0};
    	Leetcode0310 l0310 = new Leetcode0310();
    	System.out.println(l0310.validateStackSequences(pushed, popped));
    }
}
